<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    // 设计模式，实只创建一个对象
    var SingleTon = (function(){
        function Tank(){
            this.dom = null
            this.color = ''
            this.speed = 0
            this.run = function(){}
        }
        var instance = null//保存实例化对象
        return{
            getInstence(){
                // 简写方式
                // return instance ||(instance = new Tank())
                // 判断语句写
                if(instance){
                    return instance
                }else{
                    return instance = new Tank()
                }
            }
        }
    })()
    var a = SingleTon.getInstence()
    var b = SingleTon.getInstence()
    var c = SingleTon.getInstence()
    console.log(a,b,c);
    console.log(a==b);
    console.log(a==c);
    console.log(b==c);

</script>